package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SocDispatchEmpItemAddDTO;
import org.jsola.hr.dto.SocDispatchEmpItemUpdateDTO;
import org.jsola.hr.entity.SocDispatchEmpItemDO;
import org.jsola.hr.query.SocDispatchEmpItemQuery;
import org.jsola.hr.service.ISocDispatchEmpItemService;
import org.jsola.hr.vo.SocDispatchEmpItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 社保派单员工表_增员子项
 *
 * @author zhr
 */
@Component
public class SocDispatchEmpItemTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocDispatchEmpItemService socDispatchEmpItemService;

    /**
     * 生成add测试数据
     * @return SocDispatchEmpItemAddDTO
     */
    public SocDispatchEmpItemAddDTO getSocDispatchEmpItemAddDTO(){
        SocDispatchEmpItemAddDTO socDispatchEmpItemAddDTO = new SocDispatchEmpItemAddDTO();
        socDispatchEmpItemAddDTO.setSocDispatchId(getRandomValue("varchar",32));
        socDispatchEmpItemAddDTO.setEmpDispatchSocId(getRandomValue("varchar",32));
        socDispatchEmpItemAddDTO.setSocProgId(getRandomValue("varchar",32));
        socDispatchEmpItemAddDTO.setItemType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        socDispatchEmpItemAddDTO.setItemName(getRandomValue("varchar",100));
        socDispatchEmpItemAddDTO.setCardinalityPerson(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setCardinalityDefault(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setCardinalityMin(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setCardinalityMax(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setPersentCompany(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setPersentPersonal(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setAmountCompany(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setAmountPersonal(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setAmountAll(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socDispatchEmpItemAddDTO.setMantissaProcCompany(getRandomValue("varchar",100));
        socDispatchEmpItemAddDTO.setMantissaProcPersonal(getRandomValue("varchar",100));
        socDispatchEmpItemAddDTO.setItemRemark(getRandomValue("text",2147483647));
        socDispatchEmpItemAddDTO.setNoError(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socDispatchEmpItemAddDTO.setErrorMsg(getRandomValue("text",2147483647));
        socDispatchEmpItemAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        return socDispatchEmpItemAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocDispatchEmpItemUpdateDTO
     */
    public SocDispatchEmpItemUpdateDTO getSocDispatchEmpItemUpdateDTO(SocDispatchEmpItemVO socDispatchEmpItemVO){
        return socDispatchEmpItemService.selectDOById(socDispatchEmpItemVO.getId(), SITE_ID).to(SocDispatchEmpItemUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocDispatchEmpItemQuery
     */
    public SocDispatchEmpItemQuery getSocDispatchEmpItemQuery() {
        SocDispatchEmpItemQuery socDispatchEmpItemQuery = new SocDispatchEmpItemQuery();
        List<SocDispatchEmpItemDO> socDispatchEmpItemDOList = socDispatchEmpItemService.list(new SocDispatchEmpItemDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socDispatchEmpItemDOList)) {
            SocDispatchEmpItemDO socDispatchEmpItemDO = socDispatchEmpItemDOList.get(0);
            socDispatchEmpItemQuery = socDispatchEmpItemDO.to(SocDispatchEmpItemQuery.class);
            if (socDispatchEmpItemDO.getCardinalityDefault() != null) {
                socDispatchEmpItemQuery.setCardinalityDefaultStart(socDispatchEmpItemDO.getCardinalityDefault().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setCardinalityDefaultEnd(socDispatchEmpItemDO.getCardinalityDefault().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getCardinalityMin() != null) {
                socDispatchEmpItemQuery.setCardinalityMinStart(socDispatchEmpItemDO.getCardinalityMin().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setCardinalityMinEnd(socDispatchEmpItemDO.getCardinalityMin().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getCardinalityMax() != null) {
                socDispatchEmpItemQuery.setCardinalityMaxStart(socDispatchEmpItemDO.getCardinalityMax().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setCardinalityMaxEnd(socDispatchEmpItemDO.getCardinalityMax().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getPersentCompany() != null) {
                socDispatchEmpItemQuery.setPersentCompanyStart(socDispatchEmpItemDO.getPersentCompany().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setPersentCompanyEnd(socDispatchEmpItemDO.getPersentCompany().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getPersentPersonal() != null) {
                socDispatchEmpItemQuery.setPersentPersonalStart(socDispatchEmpItemDO.getPersentPersonal().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setPersentPersonalEnd(socDispatchEmpItemDO.getPersentPersonal().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getAmountCompany() != null) {
                socDispatchEmpItemQuery.setAmountCompanyStart(socDispatchEmpItemDO.getAmountCompany().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setAmountCompanyEnd(socDispatchEmpItemDO.getAmountCompany().add(new BigDecimal(1)));
            }
            if (socDispatchEmpItemDO.getAmountPersonal() != null) {
                socDispatchEmpItemQuery.setAmountPersonalStart(socDispatchEmpItemDO.getAmountPersonal().subtract(new BigDecimal(1)));
                socDispatchEmpItemQuery.setAmountPersonalEnd(socDispatchEmpItemDO.getAmountPersonal().add(new BigDecimal(1)));
            }
        }
        return socDispatchEmpItemQuery;
    }

    /**
     * 保存示例
     * @return SocDispatchEmpItemVO
     */
    public SocDispatchEmpItemVO saveSocDispatchEmpItemExample(){
        SocDispatchEmpItemAddDTO addDTO = this.getSocDispatchEmpItemAddDTO();
        SocDispatchEmpItemVO socDispatchEmpItemVO = socDispatchEmpItemService.save(addDTO,buildTokenUser());
        return socDispatchEmpItemVO;
    }


}

